package com.halflife.message;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by Administrator on 2018/4/3 0003.
 */
@RestController
@RequestMapping("mc_orderMessager")
public class OrderMessageController {

    private Logger log = LoggerFactory.getLogger(OrderMessageController.class);
    @Resource
    private OrderMessageRepository orderMessageRepository;

    //获取订单管理列表 edit by liuj3
    @GetMapping("/list")
    @ResponseStatus(HttpStatus.CREATED)
    public ResponseEntity<Map> list(@RequestParam(value = "merchantId", required = false) Integer merchantId,
                                    HttpServletRequest request) {
        Map map = new HashMap();
        try{
            HashMap<String, Object> param = new HashMap();
            if(merchantId!=null){

                param.put("merchantId", merchantId);
                List<OrderMessage> list = orderMessageRepository.selectOrderMessages(param);
                if(list.size()>0){

                    for(OrderMessage m : list){

                        m.setStatus(OrderMessage.STATUS_FINISHED);
                        orderMessageRepository.updateByPrimaryKey(m);
                    }
                }
                map.put("orderMessageList",list);
            }
        }catch (Exception e) {
            log.error(e.getMessage(), e);
            return new ResponseEntity<Map>(map, HttpStatus.INTERNAL_SERVER_ERROR);
        }
        return new ResponseEntity<Map>(map, HttpStatus.OK);
    }
}
